package com.darren.archive.service.impl;


import com.darren.archive.dao.SysDictionaryDao;
import com.darren.archive.entity.SysDictionary;
import com.darren.archive.repository.SysDictionaryRepository;
import com.darren.archive.service.SysDictionaryService;
import com.darren.framework.service.impl.GenericServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <pre>
 * *********************************************
 * Copyright DARREN
 * All rights reserved.
 * Description:
 * HISTORY:
 * *********************************************
 *  Version		Date		Author	   		Desc
 *   v1.0       2019-11-21  Darren Zhou    Create
 *
 * *********************************************
 * </pre>
 */
@Service
public class SysDictionaryServiceImpl extends GenericServiceImpl<SysDictionary, Long> implements SysDictionaryService {

    @Resource
    private SysDictionaryDao sysDictionaryDao;

    @Autowired
    private SysDictionaryRepository sysDictionaryRepository;

    @Override
    public Page<SysDictionary> findByCategoryName(String categoryName, Pageable pageable) {
        return sysDictionaryRepository.findByCategoryNameLikeOrderByCategoryNameAscItemSequenceAsc(categoryName, pageable);
    }

    @Override
    public List<SysDictionary> findByCategoryCode(String categoryCode) {
        return sysDictionaryRepository.findByCategoryCodeOrderByItemSequenceAsc(categoryCode);
    }

    @Override
    public SysDictionary save(SysDictionary entity) {
        return sysDictionaryRepository.save(entity);
//        if (entity.getId() == null) {
//            return sysDictionaryDao.save(entity);
//        } else {
//            return sysDictionaryDao.update(entity);
//        }
    }
}
